﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace xReplace
{
    class Project
    {
        private XmlDocument m_doc = null;

        public Project(String filename)
        {
            m_doc=new XmlDocument();
            m_doc.Load(filename);
        }

        public String GetKey(string key)
        {
            try
            {
                System.Xml.XmlNode node = this.m_doc.SelectSingleNode("/project/" + key);
                if (node ==null) return "";
                return node.InnerText.Trim();
            }
            catch (NullReferenceException ex)
            {
                return "";
            }
        }

        public String GetKey(string parent, string key)
        {
            try
            {
                System.Xml.XmlNode node = this.m_doc.SelectSingleNode("/project/" + parent + "/" + key);
                if (node == null) return "";
                return node.InnerText.Trim();
            }
            catch (NullReferenceException ex)
            {
                return "";
            }
        }

        public XmlNode GetNode(string key)
        {
            return this.m_doc.SelectSingleNode("/project/" + key);
        }

        public XmlNodeList GetNodeList(string key)
        {
            return this.m_doc.SelectNodes("/project/" + key);
        }

        public bool GetKeyAsBoolean(string key)
        {

            if (GetKey(key).Trim().ToLower() == "true") return true;
            return false;
        }

        public bool GetKeyAsBoolean(string parent, string key)
        {

            if (GetKey(parent, key).Trim().ToLower() == "true") return true;
            return false;
        }
    
    }
}
